package com.steve.summary.tcc;

/**
 * @Author: STEVE
 * @Description: 主程序
 * @since: 2025-05-23
 */
public class MainApp {

    public static void main(String[] args) {
        // 初始化组件
        TransactionLog transactionLog = new TransactionLog();
        TccCoordinator coordinator = new TccCoordinator(transactionLog);

        // 注册参与者
        AccountService accountService = new AccountService(transactionLog);
        InventoryService inventoryService = new InventoryService(transactionLog);

        coordinator.addParticipant(accountService);
        coordinator.addParticipant(inventoryService);

        // 执行事务
        String txId = "order_" + System.currentTimeMillis();
        boolean success = coordinator.execute(txId, 100);

        System.out.println("事务执行结果: " + success);
        System.out.println("当前余额: " + getAccountBalance());
    }

    private static int getAccountBalance() {
        // 获取测试账户余额
        return 0; // 实际应从AccountService获取
    }

}
